<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.yinbo.database.DbConnectionManager,
				java.sql.Connection,
				java.sql.SQLException,
				java.sql.Statement,
				java.sql.ResultSet,
				java.util.ArrayList,
				com.yinbo.util.Constants,
				com.yinbo.util.ParamUtils,
				org.apache.commons.lang.StringUtils,
				com.yinbo.database.JdbcTemplate,
				com.yinbo.util.DateUtils
				"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Connection connection =  DbConnectionManager.getConnection();
Statement stmt = connection.createStatement();
ResultSet rs ;

String save = ParamUtils.getParameter(request, "save",false);
Map errors = new HashMap();
if (save!=null) {
		//保存信息
		String nickname = ParamUtils.getParameter(request,"nickname",true);
		String bookpswd = ParamUtils.getParameter(request,"bookpswd",true);
		String submit_content = ParamUtils.getParameter(request,"submit_content",true);
		String submit_date = DateUtils.dateToString(new java.util.Date(),"yyyy-MM-dd  hh:mm:ss");
		String[] paras = new String[]{nickname,bookpswd,submit_content,submit_date};
		try{
			JdbcTemplate.executeUpdate("insert into book(nickname,bookpswd,submit_content,submit_date) values(?,?,?,?)",paras);
			response.sendRedirect("guestbook.jsp");
            return;
		}catch(Exception ex){
			ex.printStackTrace();
			errors.put("general","增加信息出错");
		}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>Jikey--雁过留声</title>
	<link href="styles/main.css" rel="stylesheet" type="text/css" />
	<link href="styles/common.css" rel="stylesheet" type="text/css" />
	<link href="styles/CsdnUbbEditor.css" rel="stylesheet" type="text/css" />
  </head>
  <style type="text/css">
	.error {
	    color : #900;
	    font-weight : bold;
	    background-color : #EDB9B1;
	    padding : 5px;
	    border: 1px solid #BB8888;
	    margin-top : 10px;
		margin-bottom: 20px;
	    padding-left : 28px;
	    background-image : url(images/error-16x16.gif);
	    background-repeat : no-repeat;
	    background-position : 5px 5px;
		-moz-border-radius: 3px;
	}
	</style>
	<script type="text/javascript">
	function check() {
		var nickname = document.forms[0].nickname;
		if(nickname.value == '') {
			alert("请您填写昵称!");
			nickname.focus();
			return false;
		}
		var submit_content = document.forms[0].submit_content;
		if(submit_content.value == '') {
			alert("请输入留言内容!");
			submit_content.focus();
			return false;
			}
		}
	</script>
  <body>
<% if (errors.size() > 0){ %>
  <p class="error">
  <%= errors.get("general") %>
  </p>
<%}%>
<div id="Wrap">
<%@ include file="common/menu.jsp"%>
<!--Box Start -->
  <div id="box">
  	<!--Comment Start -->
	<%
	      int i=0;
	      rs = stmt.executeQuery(" select * from book b order by b.submit_date desc limit 20");
		  while(rs.next()) {
		  	String admin=rs.getString("admin_content");
	%>
  	<div class="comment" style="margin:0;">
    	<h1><img src="images/icon_quote.gif" width="16" height="16" /><%=rs.getString("nickname") %> <span>[<%=rs.getString("submit_date") %>]</span></h1>
        <div class="commentcont">
       	  <P><%=rs.getString("submit_content") %></P>
        </div>
        <%
        if(admin != null) {
         %>
        <h1 style="border-top:none;"><img src="images/reply.gif" width="16" height="16" />admin <span>[<%=rs.getString("reply_date") %>]</span></h1>
        <div class="commentcont">
       	  <P><%=admin %></P>
        </div>
        <%
        }
         %>
    </div>
       <%
	   }
	   	if(null!=rs){rs.close();}
	   %>
    <!--Massage Start -->
      <div id="msg">
        <h1>发表留言</h1>
        <form action="guestbook.jsp" method="post" onsubmit="return check();">
        <div id="msgcont">
        	<ul>
            	<li class="liright">昵称</li>
                <li><input type="text" name="nickname" class="userpass" /></li>
            </ul>
            <ul>
            	<li class="liright">密码</li>
                <li><input type="password" name="bookpswd" class="userpass" /></li>
                <li>游客无需密码</li>
            </ul>
            <ul>
            	<li class="liright">内容</li>
                <!--<li><textarea name="submit_content" style="WIDTH:99%;HEIGHT:100px" class="editTextarea" accessKey="R"></textarea></li> -->
                <li>
                	<textarea name="submit_content" id="tb_ReplyBody___Editor" style="WIDTH:100%;HEIGHT:100px"></textarea>					
					<script type="text/javascript" src="./js/CsdnUbbEditor.js"></script>
					<script type="text/javascript">/*<![CDATA[*/
                    var ubb = new CsdnUbbEditor("tb_ReplyBody___Editor");
                    ubb.contentLength = 1600;
                    ubb.helpLink = "#";
                    //ubb.render("fontsize|space|bold|italic|underline|strikethrough|color|space|url|email|image|space|left|center|right");
                    ubb.render("fontsize|space|bold|italic|underline|strikethrough|color|code|space|url|email|swf|movie|space|left|center|right|space|increase|decrease");
                    /*]]>*/</script>
                 </li>
            </ul>
            <ul style="text-align:center; margin:-25px 0 0 20%;">            	
                <li><input class="userbutton" type="submit" value="发表留言" name="save">&nbsp;&nbsp;<input class="userbutton" type="reset" value=" 重 写 " name="button"></li>
            </ul>
        </div>
        </form>
      </div>
      <!--Massage End -->
  </div>
  
<%@ include file="common/bottom.jsp"%>
</div>
  </body>
</html>
